﻿using System.ComponentModel;
using EDMDesigner.Business.Util;

namespace EDMDesigner.Business.SSDL.Property
{
    public class Property : INotifyPropertyChanged, INamedElement
    {
        public Property(SSDL.EntityType.EntityType entityType)
        {
            EntityType = entityType;
        }

        public SSDL.EntityType.EntityType EntityType { get; private set; }

        public bool? Unicode { get; set; }
        public StoreGeneratedPattern? StoreGeneratedPattern { get; set; }
        public string StoreName { get; set; }
        public string StoreSchema { get; set; }
        public string StoreType { get; set; }

        private string _name;
        public string Name
        {
            get { return _name; }
            set 
            {
                _name = value;
                OnPropertyChanged("Name"); 
            }
        }

        private string _type;
        public string Type
        {
            get { return _type; }
            set 
            { 
                _type = value;
                OnPropertyChanged("Type");
            }
        }

        private bool _isKey;
        public bool IsKey
        {
            get { return _isKey; }
            set 
            {
                _isKey = value;
                OnPropertyChanged("IsKey");
            }
        }

        private bool? _nullable;
        public bool? Nullable
        {
            get { return _nullable; }
            set 
            {
                _nullable = value;
                OnPropertyChanged("Nullable");
            }
        }

        private int? _maxLength;
        public int? MaxLength
        {
            get { return _maxLength; }
            set 
            { 
                _maxLength = value;
                OnPropertyChanged("MaxLength");
            }
        }

        private bool? _fixedLength;
        public bool? FixedLength
        {
            get { return _fixedLength; }
            set 
            {
                _fixedLength = value;
                OnPropertyChanged("FixedLength");
            }
        }

        private int? _precision;
        public int? Precision
        {
            get { return _precision; }
            set 
            { 
                _precision = value;
                OnPropertyChanged("Precision");
            }
        }

        private int? _scale;
        public int? Scale
        {
            get { return _scale; }
            set 
            {
                _scale = value;
                OnPropertyChanged("Scale");
            }
        }

        private string _collation;
        public string Collation
        {
            get { return _collation; }
            set 
            {
                _collation = value;
                OnPropertyChanged("Collation");
            }
        }

        private string _defaultValue;
        public string DefaultValue
        {
            get { return _defaultValue; }
            set 
            {
                _defaultValue = value;
                OnPropertyChanged("DefaultValue");
            }
        }

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;

        public override string ToString()
        {
            return Name;
        }
    }
}
